package com.ruoyi.common.utils;

import java.time.Instant;
import java.util.Random;

/**
 * @author zhangye
 * @date 2025/2/25 20:12
 * @description
 */
public class CreateId {

    public static long generateId() {
        //当前时间戳
        long timestamp = Instant.now().toEpochMilli();
        long lastSixDigits = timestamp % 1000000;
        //三位随机数
        Random random = new Random();
        int randomNumber = random.nextInt(1000);
        String formattedRandomNumber = String.format("%03d", randomNumber);

        // 组合时间戳和随机数
        return Long.parseLong(lastSixDigits + formattedRandomNumber);
    }
}
